package com.own.business.exam.open;

import com.own.business.exam.business.service.ExamPaperService;
import com.own.business.exam.entity.bo.ExamPaperBo;
import com.own.business.exam.entity.map.ExamPaperMapVo;
import com.own.business.exam.entity.open.BaseOpenExamPaper;
import com.own.business.exam.entity.po.ExamPaper;
import com.own.business.exam.entity.query.ExamPaperQuery;
import com.own.business.exam.entity.vo.ExamPaperVo;
import com.own.component.common.base.open.api.BaseOpenMethod;
import com.own.component.common.model.R;
import com.own.component.common.model.ResultModel;
import lombok.NonNull;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * ExamPaperOpenMethod
 *
 * @author 陈学礼 （你是一段成熟的代码，要学会自己改bug）
 * @version 4.0.0
 * @date 2021/5/21 15:33
 * @since 4.0.0
 */
@Component
public class ExamPaperOpenMethod extends BaseOpenMethod<
        ExamPaper,
        ExamPaperBo,
        ExamPaperVo,
        ExamPaperMapVo,
        ExamPaperQuery,
        ExamPaperService
        > implements BaseOpenExamPaper {

    @Resource
    private ExamPaperService examPaperService;

    /**
     * 提交试卷
     *
     * @param userId 待获取考试的用户id
     * @param examId 考试id
     * @return 试卷信息
     */
    @Override
    public ResultModel<ExamPaperVo> submit(@NonNull Long userId, Long examId) {
        return R.success(examPaperService.submit(userId, examId));
    }

    /**
     * 根据考试id获取试卷信息
     *
     * @param userId  待获取考试的用户id
     * @param account 待获取考试的用户账号
     * @param examId  考试id
     * @return 试卷信息
     */
    @Override
    public ResultModel<ExamPaperVo> getPaperByExamId(@NonNull Long userId, @NonNull String account, Long examId) {
        return R.success(examPaperService.getPaperByExamId(userId, account, examId));
    }

    /**
     * 根据考试id获取试卷的分数信息
     *
     * @param userId 待获取考试分数的用户id
     * @param examId 考试id
     * @return 分数信息
     */
    @Override
    public ResultModel<BigDecimal> getScoreByExamId(@NonNull Long userId, Long examId) {
        return R.success(examPaperService.getScoreByExamId(userId, examId));
    }

    /**
     * 根据考试id获取试卷信息（不会生成试卷）
     *
     * @param userId 待获取试卷的用户id
     * @param examId 考试id
     * @return 试卷信息
     */
    @Override
    public ResultModel<ExamPaperVo> getResultPaperByExamId(@NonNull Long userId, Long examId) {
        return R.success(examPaperService.getResultPaperByExamId(userId, examId));
    }

    /**
     * 根据考试id获取试卷的排名信息
     *
     * @param userId 待获取考试成绩排名的用户id
     * @param examId 考试id
     * @return 分数信息
     */
    @Override
    public ResultModel<Long> getRankByExamId(@NonNull Long userId, Long examId) {
        return R.success(examPaperService.getRankByExamId(userId, examId));
    }

}
